package com.java2404.micro.merchant.handler;

import com.java2404.micro.common.dto.GoodsDTO;
import com.java2404.micro.common.entity.Merchant;
import com.java2404.micro.common.entity.PageBean;
import com.java2404.micro.common.resp.Result;
import com.java2404.micro.merchant.service.MerchantService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * 商家管理
 */
@Slf4j
@RestController
@RequestMapping("merchant")
public class MerchantHandler {


    @Resource
    private MerchantService merchantService;

    /**
     *商家登录
     */
    @PostMapping("/login")
    public Result login(@RequestBody Merchant merchant){
        Result result=merchantService.login(merchant);
        return result;
    }
    /**
     *商家注册
     */
    @PostMapping("/regist")
    public Result regist(@RequestBody Merchant merchant){
        Result result=merchantService.regist(merchant);
        return result;
    }
    /**
     *分页展示商家
     */
    @GetMapping("/ShowMerchant")
    public Result<PageBean<Merchant>> ShowMerchant(Integer pageNum, Integer pageSize){
        PageBean<Merchant> page=merchantService.ShowMerchant(pageNum,pageSize);
        return Result.success(page);}
    /**
     *更新商家信息
     */
    @PutMapping("/updateMerchant")
    public Result updateMerchant(@RequestBody Merchant merchant){
        merchantService.updateMerchant(merchant);
        return Result.success();
    }

    /**
     * 商家审核
     * 处理商家审核的业务逻辑，根据给定的商家ID和审核状态，更新商家入驻的审核状态。
     * @param mid 商家ID
     * @param mstatus 审核状态
     * @return 审核结果
     */
    @PutMapping("audit/{mid}/{mstatus}")
    public Result audit(@PathVariable("mid") int mid, @PathVariable("mstatus") int mstatus) {
        merchantService.audit(mid, mstatus);
        return Result.success();
    }


    @GetMapping("/getMerchant/{mid}")
    public Result<Merchant> getMerchant(@PathVariable("mid") int mid){
        Merchant merchant=merchantService.getById(mid);
        return Result.success(merchant);
    }
}
